---
# Configuration for MirrorManager's crawler

- name: install needed packages
  package: name={{ item }} state=present update_cache=yes
  with_items:
  - mirrormanager2-crawler
  - python-psycopg2
  - fedmsg
  - python-GeoIP
  - jq
  - geolite2-city
  - geolite2-country
  tags:
  - packages

- name: create /etc/mirrormanager
  file: path=/etc/mirrormanager state=directory

- name: install MM configuration file
  template: src={{ item.file }} dest={{ item.dest }}
              owner=mirrormanager group=mirrormanager mode=0600
  with_items:
  - { file: "{{ roles_path }}/mirrormanager/frontend2/templates/mirrormanager2.cfg",
      dest: /etc/mirrormanager/mirrormanager2.cfg }
  - { file: "{{ roles_path }}/mirrormanager/frontend2/templates/alembic.ini",
      dest: /etc/mirrormanager/alembic.ini }
  tags:
  - config

- name: install the cron job
  copy: src=crawler.cron dest=/etc/cron.d/mm2_crawler.cron
  tags:
  - config
  when: env != 'staging'

- name: install crawling helper scripts
  copy: src={{ item }} dest=/usr/local/bin/{{ item }} mode=0755
  with_items:
  - mm2_get-mirrors-to-crawl
  - run_crawler.sh
  - check_propagation.sh

# Directory used to store the result of the repomd.xml propagation test
- name: create /var/log/mirrormanager/propagation
  file: path=/var/log/mirrormanager/propagation state=directory
          owner=mirrormanager group=mirrormanager mode=0755

- name: propagation cronjob
  cron: name="propagation-check" minute="27" hour="*/2" user="mirrormanager"
        job="/usr/local/bin/check_propagation.sh"
        cron_file=propagation-check
  when: inventory_hostname.startswith('mm-crawler01.iad2')
